﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
using Webdiver;
using Microsoft.ApplicationBlocks.Data;

namespace AnyOffice.general.mobile
{
    public partial class send_manage : ModulePage
    {
        protected void btnDeleteAll_Click(object sender, EventArgs e)
        {
            SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@UserId", SqlDbType.NVarChar, 20) };
            commandParameters[0].Value = base.User.Identity.Name;
            string commandText = "DELETE [dbo].[SendedOutBox] WHERE [V1]=@UserId";
            SqlHelper.ExecuteNonQuery(base.Conn, CommandType.Text, commandText, commandParameters);
            this.litNavCount.Visible = false;
            this.litNavPager.Visible = false;
            this.btnDeleteAll.Visible = false;
            this.pnlMain.Visible = false;
            this.litMessage.Text = base.ShowMessage("无已发送手机短信");
        }
        public void ChangePage(object src, PageChangedEventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            this.BindData();
        }
        public string GetStatusDesc(int status)
        {
            switch (status)
            {
                case 0:
                    return "未发送";

                case 1:
                    return "发送成功";

                case 2:
                    return "发送失败";
            }
            return "";
        }
        public string GetUserNames(string userIds)
        {
            return StringHelper.GetUserNames(base.Conn, userIds);
        }
        private void BindData()
        {
            DataTable table = new MobileDao().SelectPaged(base.Conn, this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, false, base.User.Identity.Name);
            this.ViewState["CurrentRowNums"] = table.Rows.Count;
            this.ViewState["CurrentPage"] = this.AspNetPager1.CurrentPageIndex.ToString();
            this.rptMobile.DataSource = table;
            this.rptMobile.DataBind();
            this.litNavCount.Text = "<span class=\"small1\">共&nbsp;<span class=\"big4\">" + this.AspNetPager1.RecordCount.ToString() + "</span>&nbsp;条";
            this.litNavPager.Text = "<span class=\"small1\">当前为第" + this.AspNetPager1.CurrentPageIndex.ToString() + "页，共" + this.AspNetPager1.PageCount.ToString() + "页，每页最多" + this.AspNetPager1.PageSize.ToString() + "条</span>";
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                this.AspNetPager1.PageSize = new ConfigManager().PageSize;
                DataTable table = new MobileDao().SelectPaged(base.Conn, this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, true, base.User.Identity.Name);
                if (int.Parse(table.Rows[0][0].ToString()) == 0)
                {
                    this.litNavCount.Visible = false;
                    this.litNavPager.Visible = false;
                    this.btnDeleteAll.Visible = false;
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowMessage("无已发送手机短信");
                }
                else
                {
                    this.AspNetPager1.RecordCount = int.Parse(table.Rows[0][0].ToString());
                    this.BindData();
                    this.btnDeleteAll.Attributes.Add("onclick", "return delete_all()");
                }
            }
        }

    }
}
